package com.ee.chat.api.controller;

import com.ee.chat.api.service.ITestService;
import com.ee.chat.api.task.StatisticTask;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.service.IYieldService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("test")
public class TestController {
    private Logger log = LoggerFactory.getLogger(TestController.class);

    @Resource
    ITestService testService;
    @Resource
    IYieldService yieldService;
    @Resource
    StatisticTask statisticTask;

    /**
     * 初始化敏感词或关键词
     * @param type  0-敏感词  1-关键词
     * @return
     */
    @RequestMapping("initWord")
    public Result initWord(@RequestParam Integer type){
        try {
            return testService.initWord(type);
        } catch(Exception e){
            log.error("初始化敏感词或关键词失败", e);
        }
        return Result.returnFailure();
    }

    /**
     * 注册客服IM
     * @Author Shane
     * @Date 2020/1/20 0:13
     * @param
     * @return
     */
    @RequestMapping("registerCall")
    public Result registerCall(@RequestParam Integer userId){
        try {
            return testService.registerCall(userId);
        } catch(Exception e){
            log.error("注册客服账号失败", e);
        }
        return Result.returnFailure();
    }

    /**
     * 注册网易云IM
     * @Author Shane
     * @Date 2019/10/1420:57
     * @param
     * @return
     **/
    @RequestMapping("registerIM")
    public Result registerIM(@RequestParam String token){
        try {
            return testService.registerIM();
        }catch (Exception e){
            log.error("注册IM账号错误", e);
        }
        return Result.returnFailure();
    }

    /**
     * 测试定时器任务
     * @param timer
     * @return
     */
    @RequestMapping("testTimer")
    public Result testTimer(@RequestParam String timer){
        try{
            return testService.testTimer(timer);
        }catch (Exception e){
            log.error("【测试定时器任务错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("deleteRoom")
    public Result deleteRoom(String cid){
        try {
            return testService.deleteRoom(cid);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("kickMembers")
    public Result kickMembers(String cid, Integer userId){
        try {
            return testService.kickMembers(cid, userId);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("testYield")
    public Result testYield(){
        try {
            yieldService.handlePopYield(1339241, 0, 8800.0, 613);

            return Result.returnSuccess(null);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }


    @RequestMapping("updateImGender")
    public Result updateImGender(){
        try {
            return testService.updateImGender();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("sendMsg")
    public Result sendMsg(){
        try {
            return testService.sendMsg();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("handleCallCentent")
    public Result handleCallCentent(){
        try {
            return testService.handleCallCentent();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    /**
     * 删除指定时间之前的视频
     * @Author Shane
     * @Date 2020/8/27 14:10
     * @param
     * @return
     */
    @RequestMapping("deleteVideo")
    public Result deleteVideo(@RequestParam String beginTime, @RequestParam String endTime){
        try {
            return testService.deleteVideo(beginTime, endTime);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    /**
     * 测试websocket
     * @param msg
     * @param userId
     * @return
     */
    @RequestMapping("testWebSocket")
    public Result testWebSocket(@RequestParam String msg, @RequestParam(required = false) Integer userId){
        try {
            return testService.testWebSocket(msg, userId);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("testTop1")
    public Result testTop1(){
        try {
            return testService.testTop1();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }
    @RequestMapping("testTop2")
    public Result testTop2(){
        try {
            return testService.testTop2();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }
    @RequestMapping("testTop3")
    public Result testTop3(){
        try {
            return testService.testTop3();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }
    @RequestMapping("testTop4")
    public Result testTop4(){
        try {
            return testService.testTop4();
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("pushHostMessgae")
    public Result pushHostMessgae(@RequestParam String title, @RequestParam String content){
        try {
            return testService.pushHostMessgae(title, content);
        } catch(Exception e){
            log.error("错误", e);
        }
        return Result.returnFailure();
    }

    /**
     * 初始化数据分析
     * @Author AppiJ
     * @Date 2020/10/13 22:24
     * @param
     * @return
     */
    @RequestMapping("initDataAnalysis")
    public void initDataAnalysis(){
        try{
            statisticTask.initDataAnalysis();
        }catch (Exception e){
            log.error("【初始化数据分析错误】", e);
        }
    }

    /**
     * 回补积分提现记录
     */
    @RequestMapping("handleCreditExchange")
    public Result handleCreditExchange(@RequestParam String date){
        try{
            return testService.handleCreditExchange(date);
        }catch (Exception e){
            log.error("【回补积分提现记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新经纬度
     * @param type
     * @param lnglat
     * @param id
     * @return
     */
    @RequestMapping("updateLngLat")
    public Result updateLngLat(@RequestParam Integer type, @RequestParam String lnglat, Integer id){
        try{
            return testService.updateLnglat(type, lnglat, id);
        }catch (Exception e){
            log.error("【更新经纬度错误】", e);
        }
        return Result.returnFailure();
    }
}
